#import "MerchantDetailUI.h"
#import "NetManager.h"
#import "JSON.h"
@interface MerchantDetailUI ()

@end

@implementation MerchantDetailUI
@synthesize merchantId;
-(void)loadData{
    NSMutableDictionary*  params=@{@"merchantId":[NSString stringWithFormat:@"%d",self.merchantId]};
    
    //NSMutableDictionary * dic = [NSMutableDictionary dictionary];
    //[dic setObject:@1 forKey:@"page"];
    [NetManager POSTDataWithParams:params withUrl:@"/index.php/appMerchant/loadMerchantInfo" header:nil success:^(id object) {
        NSLog(@"%@",object);
        
        //NSString *responseStr = [[NSString alloc] initWithData:object encoding:NSUTF8StringEncoding];
        
        //NSLog(@"Request Successful, response '%@'", responseStr);
        //dic=[object JSONValue];
        dic = object;
        NSString* merchant_id=dic[@"merchant_id"];
        NSLog(@"merchant_id=======%@",merchant_id);
        NSString*  name=dic[@"name"];
        UILabel* nameLb=[[UILabel alloc] initWithFrame:CGRectMake(150, 6, 170, 25)];
        nameLb.text=[NSString stringWithFormat:@"%@",name];
        nameLb.textColor=[UIColor darkGrayColor];
        nameLb.textAlignment=NSTextAlignmentLeft;
        nameLb.font=[UIFont boldSystemFontOfSize:15];
        [self.view addSubview:nameLb];
        //
        int star=[dic[@"star"] intValue];
        if (star==5) {
            UIImageView* starView=[[UIImageView alloc] initWithFrame:CGRectMake(150, 36, 529/8, 96/8)];
            starView.image=[UIImage imageNamed:@"star5.png"];
            [self.view addSubview:starView];
        }
        if (star==4) {
            UIImageView* starView=[[UIImageView alloc] initWithFrame:CGRectMake(150, 36, 127/2, 23/2)];
            starView.image=[UIImage imageNamed:@"star4.png"];
            [self.view addSubview:starView];
        }else{
            UIImageView* starView=[[UIImageView alloc] initWithFrame:CGRectMake(150, 36, 529/8, 96/8)];
            starView.image=[UIImage imageNamed:@"star3.png"];
            [self.view addSubview:starView];
        }
        
        UILabel* distanceLb=[[UILabel alloc] initWithFrame:CGRectMake(150, 50, 170, 25)];
        distanceLb.text=@"1.2公里";
        distanceLb.textColor=[UIColor darkGrayColor];
        distanceLb.textAlignment=NSTextAlignmentLeft;
        distanceLb.font=[UIFont systemFontOfSize:15];
        [self.view addSubview:distanceLb];
        
        ////
        UIImageView* aoxianView=[[UIImageView alloc] initWithFrame:CGRectMake(3, 82, 320-6, 2.5)];
        aoxianView.image=[UIImage imageNamed:@"aoxian.png"];
        [self.view addSubview:aoxianView];
        //
        
        UIImage* send_msg=[UIImage imageNamed:@"send_msg.png"];
        UIImageView* send_msgView=[[UIImageView alloc] initWithFrame:CGRectMake((320/3-480*0.8/5)/2, 90, 480*0.8/5, 138*0.8/5)];
        send_msgView.image=send_msg;
        [self.view addSubview:send_msgView];
        
        
        //
        UIImage* gz=[UIImage imageNamed:@"gz"];
        UIImageView* gzView=[[UIImageView alloc] initWithFrame:CGRectMake(320/3+(320/3-480*0.8/5)/2, 90, 480*0.8/5, 138*0.8/5)];
        gzView.image=gz;
        [self.view addSubview:gzView];
        //
        UIImage* yedian_xiu=[UIImage imageNamed:@"yedian_xiu.png"];
        UIImageView* yedian_xiuView=[[UIImageView alloc] initWithFrame:CGRectMake((320/3-480*0.8/5)/2+640/3, 90, 480*0.8/5, 138*0.8/5)];
        yedian_xiuView.image=yedian_xiu;
        [self.view addSubview:yedian_xiuView];
        
        ////
        UIButton*  telBtn=[[UIButton alloc] initWithFrame:CGRectMake(0, 90+138*0.8/5+20, 320, 20)];
        [telBtn addTarget:self action:@selector(telFn) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:telBtn];
        
        
        UILabel*  telPreLb=[[UILabel alloc] initWithFrame:CGRectMake(30,0, 40, 20)];
        telPreLb.text=@"电话";
        telPreLb.font=[UIFont boldSystemFontOfSize:14];
        [telBtn addSubview:telPreLb];
        //
        UILabel*  telLb=[[UILabel alloc] initWithFrame:CGRectMake(80,0, 100, 20)];
        telLb.text=dic[@"mp"];
        telLb.font=[UIFont systemFontOfSize:14];
        [telBtn addSubview:telLb];
        //
        UIImageView*  telView=[[UIImageView alloc] initWithFrame:CGRectMake(209,0, 20, 20)];
        telView.image=[UIImage imageNamed:@"tel"];
        [telBtn addSubview:telView];
        
        
        
        
        
        
        
        
        //
        aoxianView=[[UIImageView alloc] initWithFrame:CGRectMake(3, 90+138*0.8/5+10+44, 320-6, 2.5)];
        aoxianView.image=[UIImage imageNamed:@"aoxian.png"];
        [self.view addSubview:aoxianView];
        //
        UIImageView* addrView=[[UIImageView alloc] initWithFrame:CGRectMake(30, 90+138*0.8/5+10+50, 102/4, 120/4)];
        
        UIImage* addrImg=[UIImage imageNamed:@"m_addr.png"];
        addrView.image=addrImg;
        [self.view addSubview:addrView];
        //
        
        
        UILabel* addrLb=[[UILabel alloc] initWithFrame:CGRectMake(80, 90+138*0.8/5+10+50, 200, 120/4)];
        
        addrLb.text=dic[@"addr"];
        
        [self.view addSubview:addrLb];
        //
        UILabel*  descLb=[[UILabel alloc] initWithFrame:CGRectMake(30, 90+138*0.8/5+10+50+50, 70, 20)];
        descLb.text=@"商家介绍";
        descLb.font=[UIFont boldSystemFontOfSize:14];
        [self.view addSubview:descLb];
        
        aoxianView=[[UIImageView alloc] initWithFrame:CGRectMake(3, 90+138*0.8/5+10+50+70, 320-6, 2.5)];
        aoxianView.image=[UIImage imageNamed:@"aoxian.png"];
        [self.view addSubview:aoxianView];
        //
        
        
        
        //
        
        UILabel*  xiaofeiLb=[[UILabel alloc] initWithFrame:CGRectMake(30, 90+138*0.8/5+10+50+140, 70, 20)];
        xiaofeiLb.text=@"消费简介";
        xiaofeiLb.font=[UIFont boldSystemFontOfSize:14];
        [self.view addSubview:xiaofeiLb];
        //
        aoxianView=[[UIImageView alloc] initWithFrame:CGRectMake(3, 90+138*0.8/5+10+50+160, 320-6, 2.5)];
        aoxianView.image=[UIImage imageNamed:@"aoxian.png"];
        [self.view addSubview:aoxianView];
        
        
    } withAnimation:YES connectionFail:^(NSError *error) {
        
    }];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView.separatorStyle=NO;
    UIButton* cancelBtn= [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 60, 44)];
    [cancelBtn addTarget:self action:@selector(backFn) forControlEvents:UIControlEventTouchUpInside];
    //
    CGRect frame_1= CGRectMake(0, 7, 40, 30);
    UIImageView*  backView=[[UIImageView alloc] initWithFrame:frame_1];
    UIImage* image= [UIImage imageNamed:@"back2015.png"];
    backView.image=image;
    [cancelBtn addSubview:backView];
    self.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc] initWithCustomView:cancelBtn];

    //
    UILabel* titleLb=[[UILabel alloc] initWithFrame:CGRectMake(100, 0, 120, 44)];
    titleLb.text=@"夜店详情";
    titleLb.backgroundColor=[UIColor clearColor];
    titleLb.textAlignment=NSTextAlignmentCenter;
    titleLb.textColor=[UIColor whiteColor];
    self.navigationItem.titleView=titleLb;
    
    
    UIImage*  merchant=[UIImage imageNamed:@"r_d_company.png"];
    UIImageView*  merchantLogoView=[[UIImageView alloc] initWithFrame:CGRectMake(5, 9, 628/5, 243/4+3)];
    merchantLogoView.image=merchant;
    [self.view addSubview:merchantLogoView];
    
    [NSThread detachNewThreadSelector:@selector(loadData) toTarget:self withObject:nil];
    
   
}


- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (buttonIndex == actionSheet.cancelButtonIndex) {
        return;
    }
    NSString *number = dic[@"mp"];
    NSString *num = [[NSString alloc] initWithFormat:@"telprompt://%@",number];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:num]];
}
- (void)telFn {
    NSString *number = dic[@"mp"];
    if(![Tools isBlankString:number]){
        UIActionSheet *sheet=[[UIActionSheet alloc] initWithTitle:number
                                                         delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"拨打电话" otherButtonTitles:nil];
        
        [sheet showInView:[UIApplication sharedApplication].keyWindow];//关键点！
    }
    
    
}


-(void)backFn{
    [self.navigationController popViewControllerAnimated:NO];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
#warning Potentially incomplete method implementation.
    // Return the number of sections.
    return 0;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
#warning Incomplete method implementation.
    // Return the number of rows in the section.
    return 0;
}

/*
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:<#@"reuseIdentifier"#> forIndexPath:indexPath];
    
    // Configure the cell...
    
    return cell;
}
*/

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
